package com.itheima.app.exception;

import com.itheima.commons.Code;
import com.itheima.commons.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 全局异常处理
 *
 * @author DogeGuo
 */
@ControllerAdvice
public class GlobalExceptionAdvice {
    /**
     * 处理自定义的异常
     *
     * @param exception
     * @return
     */
    @ExceptionHandler(BusinessException.class)
    public R handlerBusinessException(Exception exception) {
        //打印异常
        exception.printStackTrace();

        //返回错误
        return R.err(exception.getMessage());
    }

    /**
     * 处理普通异常异常
     *
     * @param exception
     * @return
     */
    @ExceptionHandler(Exception.class)
    public R handlerException(Exception exception) {
        //打印异常
        exception.printStackTrace();

        //返回错误
        return R.err("网络繁忙~~~");
    }
}